# Kinne & Marinov, "Electoral Authoritarianism and Credible Signaling
# in International Crises," Journal of Conflict Resolution.

# R script to generate Figures 1 and 2

# Note that values plugged in from Stata will vary slightly from those
# listed below, due to nature of simulation in predicted probabilities

# Figures in the paper were created in R 2.12.2 on 64-bit Mac OS X 10.6
# Script also verified in Linux Ubuntu 10.04

library(plotrix)

# FIGURE 1

pdf("fig1.pdf", width=6, height=4, paper="special")

par(mar=c(3,5,1,1))

y <- c(0.25,0.6)
x <- c(0.75,4.25)

op.m<-c(.502, .455, .371, .367)
op.se<-c(.024, .055, .049, .035)

plot(x,y,type="n",xlab="",ylab="Predicted probability of target reciprocation",cex.main=1.5, frame.plot=T,axes=F)
axis(1,1:4,tick=F,labels=c("Autocratic \n","Hegemonic \n Authoritarian","Competitive \n Authoritarian","Democratic \n"),cex.axis=1)
abline(h=0.5,col="lightgray")
abline(h=0.4,col="lightgray")
abline(h=0.3,col="lightgray")
abline(h=0.6,col="lightgray")
axis(2,at=c(0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6),cex.axis=0.9)
dispersion(1:4,op.m,op.se*1.96,lwd=1)
points(1:4, op.m, pch=19, cex=1)

dev.off()

# Can also calculate difference in means using above data
t1 <- (op.m[1]-op.m[2])/(sqrt((op.se[1]^2)+(op.se[2]^2)))
t2 <- (op.m[1]-op.m[3])/(sqrt((op.se[1]^2)+(op.se[3]^2)))
t3 <- (op.m[1]-op.m[4])/(sqrt((op.se[1]^2)+(op.se[4]^2)))

# FIGURE 2A

pdf("fig2a.pdf", width=6, height=4, paper="special")

par(mar=c(3,5,2,2),adj=0.5)

x <- c(.6088632,.7013333,.3680556,.15)
n <- c("Democracy +\nComp. Authoritarian","Democracy\n","Comp.\nAuthoritarian","Heg.\nAuthoritarian")
w <- c(.5,.5,.5,.5)
barplot(x, horiz=F, names.arg=n, width=w, ylim=c(0,1), ylab=expression(paste("Mean value of Opposition"[i]," variable")), space=.75, cex.names=.9, cex.axis=.9, axes=T)

text(c(.625,1.5,2.375,3.25),rep(.03,4),labels=c("N=519","N=375","N=144","N=100"),cex=0.8)

dev.off()

# FIGURE 2B

pdf("fig2b.pdf", width=6, height=4, paper="special")

par(mar=c(3,5,2,2),adj=0.5)

y <- c(0,0.6)
x <- c(0.75,3.25)

op.m1<-c(.397,.395,.425)
op.m2<-c(.241,.233,.193)
op.se1<-c(.0429,.0587,.0710)
op.se2<-c(.0337,.0381,.0626)

plot(x,y,type="n",xlab="",ylab="Predicted probability of target reciprocation",cex.main=1, cex.sub=1, frame.plot=T,axes=F, line=2.5)
axis(1,1:3,tick=F,labels=c("Democracy +\nComp. Authoritarian","Democracy\nOnly","Comp. Authoritarian\nOnly"),cex.axis=1)
axis(2,at=c(0,0.1,0.2,0.3,0.4,0.5,0.6),cex.axis=0.9)
abline(h=0.1,col="lightgray")
abline(h=0.3,col="lightgray")
abline(h=0.5,col="lightgray")
dispersion(c(1:3)-0.1,op.m1,op.se1*1.96,lwd=1)
points(c(1:3)-0.1, op.m1, pch=19, cex=1)
dispersion(c(1:3)+0.1,op.m2,op.se2*1.96,lwd=1)
points(c(1:3)+0.1, op.m2, pch=21, cex=1, bg="white")

dev.off()
